//
//  UserModel.m
//  FinancialProduct
//
//  Created by Stella on 2017/8/31.
//  Copyright © 2017年 maq. All rights reserved.
//

#import "UserModel.h"
static NSString *file = @"userModel_Stella_Financial.data";
@implementation UserModel
// NSCoding实现
MJExtensionCodingImplementation

+ (instancetype)userInfo:(NSDictionary *)dic{
    
    UserModel *instance = [[UserModel alloc]init];
    instance.Phone      = [dic objectForKey:@"phone"];
    instance.CustomerName       = [dic objectForKey:@"CustomerName"];
    instance.Accountstatus=dic[@"Accountstatus"];
    instance.CustomerID=dic[@"CustomerID"];
    return instance;
    
//    return  [UserModel mj_objectWithKeyValues:dict];
}

/**储存用户信息**/
-(void)save{
    NSString *userfile = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:file];
    // Encoding
    //NSLog(@"save===%@",userfile);
    [NSKeyedArchiver archiveRootObject:self toFile:userfile];
    
}

/**获取用户模型**/
+(UserModel *)getUser{
    NSString *userfile = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:file];
    UserModel *decodedUser = [NSKeyedUnarchiver unarchiveObjectWithFile:userfile];
    return decodedUser;
}

/**判断用户是否登录**/
+ (BOOL)isLogin{
    NSUserDefaults*user = [NSUserDefaults standardUserDefaults];
    return [user boolForKey:@"USERISLOGINKEY"];
}

/**设置用户是否登录  YES为登录  NO为没有登录**/
+(void)setUserLogin:(BOOL)login{
    NSUserDefaults*user = [NSUserDefaults standardUserDefaults];
    [user setBool:login forKey:@"USERISLOGINKEY"];
    [user synchronize];
}
@end
